SRC           = $(shell find . -name '*.[cS]')
OBJ           = $(SRC:%=%.o)

CC            = arm-elf-gcc
CFLAGS        = -Wall -fno-builtin -I../lib/ -g
LD            = arm-elf-ld
LDFLAGS	      = -L../lib 
LSCRIPT       = link_sdram.ld
OBJCOPY       = arm-elf-objcopy
MKIMAGE       = arm-elf-ar
MKIMAGE_FLAGS = crvs
IMAGE         = kernel
BOOTIMAGE     = system.img
DEPENDFILE    = depend

all:	$(BOOTIMAGE)

.PHONY: clean dep

clean:
	rm -f *.o *~
	rm -f process1/*.o process1/*~
	rm -f process2/*.o process2/*~
	rm -f $(IMAGE) $(IMAGE).bin $(BOOTIMAGE)

%.c.o: %.c
	$(CC) $(CFLAGS) -o $@ -c $<

%.S.o: %.S 
	$(CC) $(CFLAGS) -o $@ -c $<

dep: $(SRC)
	$(CC) -MM $(SRC) > $(DEPENDFILE)

-include $(DEPENDFILE)

$(IMAGE): $(OBJ)
	$(LD) $(LDFLAGS) -T$(LSCRIPT) -o $@ $^ -lA
	$(OBJCOPY) $@ -Obinary $@.bin

$(BOOTIMAGE): $(OBJ)
	$(MKIMAGE) $(MKIMAGE_FLAGS) libP.a $(OBJ)

zoo:
	make -C process1 affe
	make -C process2 giraffe
	mk_ramdisk process1/affe.esel process2/giraffe.esel > elefantenstorch.c
